#!/usr/bin/python
# coding=utf8
#
# Copyright (C) 2011 XNData contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys, os
sys.path.append (os.getcwd () + '/../../')
import xndata.client
import xndata.client.info
import unittest
import random
import datetime

class XNInfoClientTestCase (unittest.TestCase):

    def setUp (self):
        self.client = xndata.client.info.XNInfoClient (uname="zhangchitc@gmail.com", upass="aaaaaaaa")


    def testPassLogin (self):
        client = xndata.client.info.XNInfoClient (uname="zhangchitc@gmail.com", upass="aaaaaaaa")
        self.assertEqual (client.user_id, "242124580")
        self.assertEqual (client.user_name, "张弛")

    def testClientLogin (self):
        client = xndata.client.XNClient ("zhangchitc@gmail.com", "aaaaaaaa")
        pClient = xndata.client.info.XNInfoClient (xnclient=client)
        self.assertEqual (pClient.user_id, "242124580")
        self.assertEqual (pClient.user_name, "张弛")


    def test_get_total_friend (self):
        # Shao shan's friend
        self.assertTrue (self.client.getTotalFriend ("236136023") >= 0)
        # My album
        self.assertTrue (self.client.getTotalFriend ("242124580") >= 900)

    def test_get_profile (self):
        # Ren Su Yi's profile
        profile = self.client.getProfile ("247780420")
        self.assertEqual (profile.uid, "247780420")
        self.assertEqual (profile.name, "任素仪Silvia")
        self.assertEqual (profile.sex, "女")
        self.assertEqual (profile.birth, datetime.date (1990, 9, 19))
        self.assertEqual (profile.hometown_p, "浙江")
        self.assertEqual (profile.hometown_c, "杭州市")
        self.assertEqual (profile.college, "南京大学")
        self.assertEqual (profile.college_grad, 2008)
        self.assertEqual (profile.college_dept, "西班牙语系")
        self.assertEqual (profile.highschool, "浙江省杭州学军中学")
        self.assertEqual (profile.primaryschool, "杭州市阳光小学")
        self.assertEqual (profile.qq, "519360586")


suite1 = unittest.TestLoader().loadTestsFromTestCase (XNInfoClientTestCase)
allsuite = unittest.TestSuite ([suite1])

unittest.TextTestRunner(verbosity=2).run(allsuite)

